/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.agh.air.bpel2bpmn.walker;

import org.agh.air.bpel2bpmn.comparator.AbstractComparator;
import org.agh.air.bpel2bpmn.comparator.impl.CaseComparator;
import org.agh.air.bpel2bpmn.comparator.impl.DeferredChoiceComparator;
import org.agh.air.bpel2bpmn.comparator.impl.ExclusiveChoiceComparator;
import org.agh.air.bpel2bpmn.comparator.impl.MultipleMergeComparator;
import org.agh.air.bpel2bpmn.comparator.impl.OnAlarmComparator;
import org.agh.air.bpel2bpmn.comparator.impl.OnMessageComparator;
import org.agh.air.bpel2bpmn.comparator.impl.ParallelSplitComparator;
import org.agh.air.bpel2bpmn.comparator.impl.OtherwiseComparator;
import org.agh.air.bpel2bpmn.comparator.impl.SequenceComparator;
import org.agh.air.bpel2bpmn.comparator.impl.SimpleMergeComparator;
import org.agh.air.bpel2bpmn.comparator.impl.SwitchComparator;
import org.agh.air.bpel2bpmn.comparator.impl.SynchronizationComparator;
import org.agh.air.bpel2bpmn.exception.ImproperInputFileException;
import org.agh.air.bpel2bpmn.exception.PatternNotFoundException;
import org.apache.log4j.Logger;
import org.w3c.dom.Node;

/**
 *
 * @author paletz
 */
public class ComparatorInvoker {

    private static final Logger logger = Logger.getLogger(Class.class);
    
    private static AbstractComparator[] comparators = new AbstractComparator[]{ 
        new OnMessageComparator(),
        new OnAlarmComparator(),
        new MultipleMergeComparator(),
        new DeferredChoiceComparator(),
        new SynchronizationComparator(), 
        new CaseComparator(),
        new OtherwiseComparator(), 
        new ExclusiveChoiceComparator(), 
        new SwitchComparator(), 
        new SimpleMergeComparator(), 

        new SequenceComparator(), 
        new ParallelSplitComparator(),
    };

    public static String invoke(Node node) throws ImproperInputFileException{
        
        for(AbstractComparator comparator : comparators){
            try {
                return comparator.compare(node);
            } catch (PatternNotFoundException ex) {
                logger.error(ex, ex);
            }
        }
        
        throw new ImproperInputFileException();
    }
    
}

